package 力扣日常刷题.木22一月.第15天0127;

/**
 * @author 帅小伙
 * @date 2022/1/27
 * @description
 */
public class Demo08中等字符串执行所有后缀指令 {

    public int[] executeInstructions(int n, int[] startPos, String s) {
        int[] res = new int[s.length()];
        int start = startPos[0];
        int end = startPos[1];
        int index = 0;
        for(int i = 0; i < s.length(); i++){
            int x = start;
            int y = end;
            int count = 0;
            for(int j = i; j < s.length(); j++){
                if (s.charAt(j) == 'R') {
                    if (y + 1 == n) {
                        break;
                    }else {
                        y++;
                        count++;
                    }
                }
                if (s.charAt(j) == 'D') {
                    if (x + 1 == n) {
                        break;
                    }else{
                        x++;
                        count++;
                    }
                }
                if (s.charAt(j) == 'L') {
                    if (y - 1 < 0) {
                        break;
                    }else{
                        y--;
                        count++;
                    }
                }
                if (s.charAt(j) == 'U') {
                    if (x - 1 < 0) {
                        break;
                    }else{
                        x--;
                        count++;
                    }
                }
            }
            res[index++] = count;
        }
        return res;

    }

}
